package com.dhp.controller;


import com.dhp.entity.User;
import com.dhp.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-12-06
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    IUserService userService;
    @Autowired
    BCryptPasswordEncoder passwordEncoder;

    @PostMapping("/save")
    public boolean save(@RequestBody User user){
        //添加用户时，密码会经过加密处理
        String password = user.getPassword();
        user.setPassword(passwordEncoder.encode(password));
        return userService.save(user);
    }
}

